package day05.integer;

public class Lian05 {
    public static void main(String[] args) {
        int[]arr={1,2,3,4,5,6,7,};
        int num=2;
        int index=binarySearchForIndex(arr,num);
        System.out.println(index);
    }

    private static int binarySearchForIndex(int[] arr, int num) {
        int min=0;
        int max=arr.length-1;
        while (min<=max){
            int mid=(max+min)>>1;
            if (arr[mid]>num){
                max=mid-1;
            }else if (arr[mid]<num){
                min=mid+1;
            }else {
                return mid;
            }

            }
        return -1;
        }
    }

